<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<title>Madhouse|monitor core</title>
<link rel="stylesheet" href="../assets/css/bootstrap-spacelab.css" />
<link rel="stylesheet" href="../assets/css/base.css?t=20130516173114" />
<link rel="stylesheet" href="../assets/css/validationEngine.jquery.css" type="text/css"/>
  <!-- template
    ================================================== -->
    <script id="t_a" type="text/html">
				<form class="form-horizontal" id="form" onsubmit="return false;">
					 <fieldset>
					 	<legend>服务端</legend>
					 	<br />
                        <div class="control-group">
                            <label class="control-label" for="watchdogUrl"> Watchdog URL： </label>
                            <div class="controls">
                                <input type="text" class="validate[required,custom[url]] text-input"  name="watchdogUrl" value="<%= json.engine.watchdogUrl %>" style="width:540px;" >
                                <p class="help-block">watchdog是部署在监控服务端机房外的，检查监控服务可靠性的一个CGI</p>
                            </div>
                        </div>
						
					 </fieldset>
					 
					 <fieldset>	
					 <legend>客户端</legend>
					 	
                        <div class="control-group">
                            <label class="control-label" for="sleepSecPerReq"> 客户端请求间隔秒数： </label>
                            <div class="controls">
                                <input type="text" class="validate[required,custom[integer1]] text-input" name="sleepSecPerReq" value="<%= json.client.sleepSecPerReq %>" >
                            </div>
                        </div>
						
					 </fieldset>
					 
					 <fieldset>	
					 <legend>日常</legend>	
					 
                     <div class="control-group">
                         <label class="control-label" for="optionsCheckbox">发送server状态邮件：</label>
                         <div class="controls">
                             <label class="checkbox inline">
                                 <input type="checkbox" name="sendMail" <%= json.daily.sendMail == 1 && 'checked' %> >&nbsp;
                             </label>
                         </div>
					</div>
											 
                        <div class="control-group">
                            <label class="control-label" for=""> 每天：</label>
							<div class="controls" >
								<select name="sendHour" style="width:5em;">
										<% for(var i = 0,j; i < 24; i++){
											 j = i < 10 ? '0' + i : i; %>
					 						<option value="<%= j %>" <%= json.daily.sendHour == i && 'selected' %> ><%= j %></option>
										<% } %>
					 			</select> &nbsp; : &nbsp;
								<select name="sendMin" style="width:5em;">
										<% for(i = 0,j; i < 60; i++){
											 j = i < 10 ? '0' + i : i; %>
					 						<option value="<%= j %>" <%= json.daily.sendMin == i && 'selected' %> ><%= j %></option>
										<% } %>
					 			</select>								
                            </div>
                        </div>																								

				</fieldset>
				
                <div class="form-actions">
                    <button class='btn btn-info' name="submit">
                        	保存 
                    </button>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button class='btn' name="reset">
                        	重置 
                    </button>					
					<input type="reset" style="display:none;">
                </div>			
			</form>
			
    </script>

	
<style>

</style>

</head>
<body>
    <header>
        <h1><span id="title">常规设置</span></h1>
        <div class="row" id="toolbar">
                <div class="box_1">
                    <button class="btn" id="info" data-toggle="modal" data-target="#modal"  data-keyboard="true" data-backdrop="true">
                        <i class="icon-info-sign"></i> 信息
                    </button>					
                </div>
				
                <div class="btn-group" style="display:none;">
                    <button class="btn">
                        	操作
                    </button>
                    <button class="btn dropdown-toggle" data-toggle="dropdown">
                        <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="#" id="notification"></a></li>
                    </ul>
                </div>
        </div>
    </header>	
	
    <div id="mainbody">
        <div class="tab-pane active" id="set_form">
        </div>
    </div>
	

  <!-- 弹出对话框
    ================================================== -->
<div class="modal fade" id="modal">
  <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3>help</h3>
  </div>
  <div class="modal-body">
  		此页面用于修改监控系统的常规设置.
  </div>
  <div class="modal-footer">
    <a href="#" class="btn"  data-dismiss="modal">关闭</a>
  </div>
</div>


  <!-- js part
    ================================================== -->
<script src="../assets/js/library/jquery-1.7.1.js"></script>
<script src="../assets/js/library/bootstrap.min.js"></script>
<script src="../assets/js/library/template.js"></script>
<script src="../assets/js/library/jquery.validationEngine-en.js"></script>
<script src="../assets/js/library/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/js/helper.js?t=20130516173114"></script>
<script src="../assets/js/doc.js?t=20130516173114"></script>	
<script>
$(function(){
	
	var smartMad = window.smartMad = window.smartMad || {};
	
	////////////////////////////////////////////////////
	//常规选项设置
	////////////////////////////////////////////////////
	var formConf = {
		url: smartMad._url + smartMad.api.getGenericSet
	};	
	var formCall = function(e,json){
		var $th = $(this), data, html;
		
		//$th.html(JSON.stringify(json));return;
        ///////////////////////////////////////////////
		
        data = {
            json: json
        };
        
        ///////////////////////////////////////////////
        
        html = template('t_a', data);
        $th.html(html);
		
		$('#form').validationEngine();
		
	};	
	
	
	////////////////////////////////////////////////////////
	//提交保存
	////////////////////////////////////////////////////////
    $('#mainbody')
	.delegate('button[name="submit"]', 'click', function(){
		//表单验证
		if(!$('#form').validationEngine('validate')){
			return;
		}
		
        var conf = {
			url: smartMad._url + smartMad.api.updateGenericSet
        };
		
        var watchdogUrl = $('input[name="watchdogUrl"]').val(),
		    sleepSecRep = $('input[name="sleepSecPerReq"]').val() * 1,
        	sendMail = $('input[name="sendMail"]').attr('checked') ? 1 : 0,
			sendHour = $('select[name="sendHour"]').val(),
			sendMin = $('select[name="sendMin"]').val(),
			sendSec = '00';
		
       conf.data = {
                'watchdogUrl': watchdogUrl,
                'sleepSecPerReq': sleepSecRep,
                'sendMail': sendMail,
                'sendHour': sendHour,
                'sendMin': sendMin,
                'sendSec': sendSec
            };	
		
        $(this).postData(conf);
    })
	.delegate('button[name="reset"]', 'click', function(){
		//$('#set_form').getData(formConf);
	});
    
	////////////////////////////////////////////////////////
	//init
	////////////////////////////////////////////////////////
	
	$('#set_form').bind('ajax.success', formCall).getData(formConf);
});
</script>
</body>
</html>
